package com.ouc.openplatform.pampas;
import java.io.Serializable;
public class Response<T> implements Serializable
{
  private static final long serialVersionUID = 6138979130005367537L;
  private boolean success;
  private T result;
  private String error;
  
  public String toString()
  {
    return "Response(success=" + isSuccess() + ", result=" + getResult() + ", error=" + getError() + ")";
  }
  
  public boolean isSuccess()
  {
    return this.success;
  }
  
  public void setSuccess(boolean success)
  {
    this.success = success;
  }
  
  public T getResult()
  {
    return this.result;
  }
  
  public String getError()
  {
    return this.error;
  }
  
  public void setResult(T result)
  {
    this.success = true;
    this.result = result;
  }
  
  public void setError(String error)
  {
    this.success = false;
    this.error = error;
  }
  
  public static <T> Response<T> ok(T data)
  {
    Response<T> resp = new Response();
    resp.setResult(data);
    return resp;
  }
  
  public static <T> Response<T> ok()
  {
    return ok(null);
  }
  
  public static <T> Response<T> fail(String error)
  {
    Response<T> resp = new Response();
    resp.setError(error);
    return resp;
  }
}
